<div id="message" class="alert alert-info bigger-110">

</div>
<script>
    function init_dialog() {
        console.debug('starting to initialize confirm dialog!!!');

        var dialog_template_label = $('#dialog_template_label');
        dialog_template_label.find('span').remove();
        dialog_template_label.append('<span class="red"><i class="icon-warning-sign"></i> Warning</span>');

        $('#message').append('{{ message | safe}}');


        {# ***************************************************************** #}
        {# Submit Button #}
        $('#dialog_template_submit_button').on('click', function (e) {
            e.stopPropagation();
            e.preventDefault();

            // disable the submit_button
            var submit_button = $(this);


            var url;
            url = '{{ action }}';

            console.debug('url: '+url)

            if(url==''){
                $('#dialog_template').modal('hide');
            }
            else{
                submit_button.button('loading');

                $.post(url).done(function (response) {
                    $('#dialog_template').modal('hide');
                    // reload page
                    setTimeout(function () { // wait for hide event to finish
                        window.location.reload();
                    }, 0);
                }).fail(function (jqXHR) {
                            bootbox.alert('<h6 class="red"><i class="icon-warning-sign"></i> Failed</h6>' +jqXHR.responseText);
                            submit_button.button('reset');
                        });
            }
        });


        $('.date').each(function () {
            var date = moment.utc($(this).text());
            $(this).text(date.fromNow());
        });


        console.debug('finished initializing the confirm dialog!')
    }
</script>


<script type="text/javascript">
    function destruct_dialog() {



        $('#dialog_template_submit_button').unbind();

        $('#dialog_template').data('modal', null);

    }
</script>
